9783c1c66fd547470ebbd75a956fab4b0a31135a,clients/unshaded/src/main/java/tachyon/client/block/TachyonBlockStore.java,TachyonBlockStore,getInStream,#number#,87
Before Change
NetAddress workerNetAddress = blockInfo.locations.get(0).getWorkerAddress();
InetSocketAddress workerAddr =
new InetSocketAddress(workerNetAddress.getHost(), workerNetAddress.getDataPort());
if (NetworkAddressUtils.getLocalHostName(ClientContext.getConf()).equals(
workerAddr.getHostName())) {
if (mContext.hasLocalWorker()) {
return new LocalBlockInStream(blockId, blockInfo.getLength(), workerAddr);
After Change
// Although blockInfo.locations are sorted by tier, we prefer reading from the local worker.
// But when there is no local worker or there are no local blocks, we prefer the first
// location in blockInfo.locations that is nearest to memory tier.
String localHostName = NetworkAddressUtils.getLocalHostName(ClientContext.getConf());
for (BlockLocation location : blockInfo.locations) {
NetAddress workerNetAddress = location.getWorkerAddress();
if (workerNetAddress.getHost().equals(localHostName)) {
if (mContext.hasLocalWorker()) {
// There is a local worker and the block is local.
return new LocalBlockInStream(blockId, blockInfo.getLength(),
new InetSocketAddress(workerNetAddress.getHost(), workerNetAddress.getDataPort()));
} else {
throw new IOException("Attempts to read a local block but there is no local worker.");
}